const DoublyLinkedList = require("../template.js")

/** 2. 查找方法测试 */
function testFind() {
  const link = DoublyLinkedList.fromArray(["a", "b", "c"])
  // console.log(link, "link")

  // 测试索引查找
  console.log("2.1 查找索引0:", link.findByIndex(0).value === "a")
  console.log("2.2 查找索引2:", link.findByIndex(2).value === "c")

  // 测试值查找
  console.log(
    "2.3 查找值'b':",
    link.findByValue("b").prev === link.findByValue("a")
  )
  const _testfindValue = function () {
    const objList = new DoublyLinkedList()
    const obj = { key: "value" }
    objList.append(obj)
    return objList.findByValue(obj).value === obj
  }
  console.log("2.4 查找对象值:", _testfindValue())
  console.log("--------------------")
}

testFind()

module.exports = testFind
